﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace UpperComputer.WPF.Entry.Controls
{
    /// <summary>
    /// CommunicationStatus.xaml 的交互逻辑
    /// </summary>
    public partial class CommunicationStatus : UserControl
    {
        private static readonly DependencyProperty StatusProperty = DependencyProperty.Register(nameof(Status), typeof(bool), typeof(CommunicationStatus), new PropertyMetadata(false, PropertyChangedCallback, null));

        [Bindable(true), Category("自定义属性"), Description("通信状态")]
        public bool Status
        {
            get => (bool)GetValue(StatusProperty); 
            set => SetValue(StatusProperty, value); 
        }

        public CommunicationStatus()
        {
            InitializeComponent();
        }

        private static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue == null)
            {
                return;
            }
            bool status = (bool)e.NewValue;
            ((CommunicationStatus)d).StatusEllipse.Fill = new SolidColorBrush(status ? Colors.Green : Colors.Red);
        }
    }
}
